<template>
  <div>
    <!-- 面包屑导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>维修信息</el-breadcrumb-item>
      <el-breadcrumb-item>异常单</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="5">
          <el-input
            placeholder="请输入报修人id"
            v-model="queryInfo.userNumber"
            clearable
            @clear="getErrorBillList"
          >
          </el-input>
        </el-col>

        <el-col :span="5">
          <el-input
            placeholder="请输入楼栋"
            v-model="queryInfo.building"
            clearable
            @clear="getErrorBillList"
          >
          </el-input>
        </el-col>

        <el-col :span="5">
          <el-select
            clearable
            @clear="getErrorBillList"
            v-model="queryInfo.repairType"
            placeholder="请选择维修类型"
            style="width: 100%"
          >
            <el-option label="电类故障" value="电类故障"></el-option>
            <el-option label="水类故障" value="水类故障"></el-option>
            <el-option label="木工类故障" value="木工类故障"></el-option>
            <el-option label="电梯故障" value="电梯故障"></el-option>
            <el-option label="空调故障" value="空调故障"></el-option>
            <el-option label="洗衣机故障" value="洗衣机故障"></el-option>
            <el-option label="直饮水故障" value="直饮水故障"></el-option>
            <el-option label="热水故障" value="热水故障"></el-option>
            <el-option label="其他类故障" value="其他类故障"></el-option>
          </el-select>
        </el-col>

        <el-col :span="3">
          <el-button type="primary" @click="getErrorBillList()"
            >开始查询</el-button
          >
        </el-col>
      </el-row>

      <!-- 表格数据区域 -->
      <el-table :data="errorBillList" stripe border>
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="userNumber" label="报修人"> </el-table-column>
        <el-table-column prop="building" label="楼栋"> </el-table-column>
        <el-table-column prop="number" label="宿舍号"> </el-table-column>
        <el-table-column prop="repairType" label="维修类型"> </el-table-column>
        <el-table-column prop="reportTime" label="报修时间"> </el-table-column>
        <el-table-column width="200px" prop="address" label="操作">
          <template slot-scope="scope">
            <!-- 编辑用户 -->
            <el-tooltip
              effect="dark"
              content="查看详情"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="primary"
                icon="el-icon-chat-line-square"
                :disabled="flag"
                size="mini"
                @click="showDetailDialog(scope.row)"
              ></el-button>
            </el-tooltip>

            <el-tooltip
              effect="dark"
              content="异常详情"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="danger"
                icon="el-icon-warning-outline"
                :disabled="flag"
                size="mini"
                @click="showErrorDialog(scope.row.mainId)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pageNum"
        :page-sizes="[2, 3, 6, 10]"
        :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 展示详细信息的对话框 -->
    <el-dialog
      title="详细信息"
      :visible.sync="showDetailDialogVisible"
      width="50%"
      @close="showDetailDalogClose"
    >
      <div class="demo-image__placeholder">
        <div class="block">
          <span class="demonstration" style="font-family: 100px Extra large"
            ><h2>报修描述：{{ detail.description }}</h2></span
          >
          <el-image :src="detail.imageUrl">
            <div slot="placeholder" class="image-slot">
              加载中<span class="dot">...</span>
            </div>
          </el-image>
        </div>
      </div>
    </el-dialog>

    <!-- 查看异常信息对话框 -->
    <el-dialog title="异常信息" :visible.sync="errorDialogVisible" width="50%">
      <!-- 主体 -->
      <el-form
        :hide-required-asterisk="true"
        :model="errorForm"
        label-width="70px"
      >
        <el-form-item prop="errorReason" label="原因">
          <el-input
            maxlength="50"
            show-word-limit
            type="textarea"
            readonly
            v-model="errorForm.errorReason"
          ></el-input>
        </el-form-item>
        <el-form-item prop="errorSuggest" label="建议">
          <el-input
            readonly
            maxlength="50"
            show-word-limit
            type="textarea"
            v-model="errorForm.errorSuggest"
          ></el-input>
        </el-form-item>
        <el-form-item prop="errorDetail" label="详情">
          <el-input
            readonly
            maxlength="50"
            show-word-limit
            type="textarea"
            v-model="errorForm.errorDetail"
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: { pageSize: 6 },
      errorBillList: [],
      total: 0,
      flag: true,
      showDetailDialogVisible: false,
      detail: { imageUrl: "", description: "" },
      errorForm: {},
      errorDialogVisible: false,
    };
  },
  methods: {
    //获取表格信息
    async getErrorBillList() {
      const { data: res } = await this.$http.get("repairbill/getErrorBill/", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) {
        return this.$message.error("请求用户数据失败");
      }
      this.errorBillList = res.data.records;
      this.total = res.data.total;
    },

    // 页大小的变化
    handleSizeChange(newsize) {
      this.queryInfo.pageSize = newsize;
      this.getErrorBillList();
    },
    // 页面值的变化
    handleCurrentChange(newPagenum) {
      this.queryInfo.pageNum = newPagenum;
      this.getErrorBillList();
    },
    showDetailDialog(row) {
      this.showDetailDialogVisible = true;
      this.detail.imageUrl = row.reportImage;
      this.detail.description = row.reportDesc;
    },
    showDetailDalogClose() {
      this.detail.imageUrl = "";
      this.detail.description = "";
    },
    async showErrorDialog(id) {
      const { data: res } = await this.$http.get(
        "/repairbill/getErrorBillDetailById/" + id
      );
      if (res.meta.status !== 200) {
        return this.$message.error("异常信息获取失败");
      }
      this.errorForm = res.data;
      this.errorDialogVisible = true;
    },
  },
  created() {
    this.getErrorBillList();
    this.flag =
      JSON.parse(sessionStorage.getItem("user")).identity !== "管理员";
    console.log(this.flag);
  },
};
</script>

<style></style>
